package pl.bmajsak.dzone.pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;

/**
 * 
 * <a href="http://code.google.com/p/selenium/wiki/PageObjects" title="Page Object">Page Object</a>
 * encapsulating user's search available on dzone.com main page.
 * 
 * @author Bartosz Majsak
 *
 */
public class DzoneMainPage {

	private static final String DZONE_PAGE = "http://dzone.com";

	private final WebDriver driver;

	@FindBy(how = How.ID, using = "mh_searchQuery")
	@CacheLookup
	private WebElement searchBox;
	
	@FindBy(how = How.ID, using = "mh_searchSubmit")
	@CacheLookup
	private WebElement searchButton;
	
	public DzoneMainPage(WebDriver driver) {
		this.driver = driver;
		driver.get(DZONE_PAGE);
	}
	
	public DzoneSearchResultPage searchFor(String query) {
		searchBox.sendKeys(query);
		searchButton.click();
		return PageFactory.initElements(driver, DzoneSearchResultPage.class);
	}
}
